package org.example.dubbo.samples.annotation.impl;

import org.apache.dubbo.config.annotation.DubboService;
import org.example.dubbo.samples.annotation.AnnotationConstants;
import org.example.dubbo.samples.annotation.api.GreetingService;

import java.util.concurrent.CompletableFuture;

@DubboService(version = AnnotationConstants.VERSION)
public class AnnotationGreetingServiceImpl implements GreetingService {
    @Override
    public String greeting(String name) {
        System.out.println("provider received invoke of greeting: " + name);
        sleepWhile();
        return "Annotation, greeting " + name;
    }

    @Override
    public String replyGreeting(String name) {
        System.out.println("provider received invoke of replyGreeting: " + name);
        sleepWhile();
        return "Annotation, fine " + name;
    }

    @Override
    public CompletableFuture<String> greeting(String name, byte signal) {
        return GreetingService.super.greeting(name, signal);
    }

    private void sleepWhile() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
